<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('标签列表')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="config-form">
                <div class="select-list">
                    <ul>
                        <li>
                            名称：<input type="text" name="tagTitle"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addTag()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary btn-edit single disabled" onclick="updateTag()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-trash"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "blog/tag";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "createTime",
            sortOrder: "desc",
            changeSupportUrl: prefix + "/support",
            modalName: "标签",
            columns: [{
                field: 'state',
                checkbox: true
            }, {
                field: 'tagId',
                title: '标签ID'
            }, {
                field: 'tagTitle',
                title: '名称',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'count',
                title: '关联blog数',
                align: 'center',
                formatter: function (value, row, index) {
                    return '<span class="badge badge-info">' + value + '</span>';
                },
                sortable: true
            }, {
                field: 'createTime',
                title: '创建时间',
                sortable: true
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="updateTag(\'' + row.tagId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tagId + '\')"><i class="fa fa-remove"></i> 删除</a>');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    function addTag() {
        var url = prefix + '/add';
        $.modal.open("添加Tag", url, '500', '300');
    }

    function updateTag(id) {
        if ($.common.isEmpty(id) && $.table._option.type == table_type.bootstrapTreeTable) {
            var row = $('#' + $.table._option.id).bootstrapTreeTable('getSelections')[0];
            if ($.common.isEmpty(row)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var url = $.table._option.updateUrl.replace("{id}", row[$.table._option.uniqueId]);
            $.modal.open("修改" + $.table._option.modalName, url);
        } else {
            $.modal.open("修改" + $.table._option.modalName, $.operate.editUrl(id), '500', '300');
        }
    }
</script>
</body>
</html>